
public class Solution {
    public static void main(String[] args) {
        String[] strs = {"abc","ab","abd"};
        System.out.println(new Solution().longestCommonPrefix(strs));
    }
    public String longestCommonPrefix(String[] strs) {
        if(strs == null|| strs.length==0){
            return "";
        }
        int i =1;
        String pre = strs[0];
        while(i < strs.length){
            while(strs[i].indexOf(pre)!=0){
                pre = pre.substring(0,pre.length()-1);
            }
            i++;
        }
        return pre;
    }
}